Guided Practice 4.2 - Solution

The question was:

In the following examples, assume the value of lst1 is (list 11 22 33).

1. Which of the following is the value of (cons 44 lst1)?

a. (list 44 11 22 33)
b. (list (list 44) 11 22 33)
c. (list 44)
d. (list 11 22 33)
e. 44
f. (list 44 55 11 22 33)

The correct answer is: (list 44 11 22 33).
Consing a value onto a list creates a new list whose first element is
that value.

2. Which of the following is the value of (append (list 44 55) lst1)?

a. (list 44 11 22 33)
b. (list (list 44) 11 22 33)
c. (list 44)
d. (list 11 22 33)
e. 44
f. (list 44 55 11 22 33)

The correct answer is: (list 44 55 11 22 33).
Appending two lists concatenates their values.

3. Which of the following is the value of (append (list 44) lst1)?

a. (list 44 11 22 33)
b. (list (list 44) 11 22 33)
c. (list 44)
d. (list 11 22 33)
e. 44
f. (list 44 55 11 22 33)

The correct answer is: (list 44 11 22 33). Appending two lists
concatenates their values. If the first list has only one element,
then the result is the same as if you had consed that element onto the
list. Never say (append (list a) lst1); say (cons a lst1) instead. 

4. Which of the following is the value of (first (cons 44 lst1))?

a. (list 44 11 22 33)
b. (list (list 44) 11 22 33)
c. (list 44)
d. (list 11 22 33)
e. 44
f. (list 44 55 11 22 33)

The correct answer is: 44. (cons v lst) builds a list whose first element is v.

5. Which of the following is the value of (rest (cons (list 44) lst1))?

a. (list 44 11 22 33)
b. (list (list 44) 11 22 33)
c. (list 44)
d. (list 11 22 33)
e. 44
f. (list 44 55 11 22 33)

The correct answer is: (list 11 22 33). (cons v lst) builds a list whose rest is lst.

Last modified: Wed Aug 24 21:53:59 Eastern Daylight Time 2016